home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / lib / python2.5 / hotshot / stats.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-29  |  3KB  |  101 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.5)
  3.  
  4. '''Statistics analyzer for HotShot.'''
  5.  
  6. try:
  7.     import profile
  8.     import pstats
  9. except ImportError:
  10.     e = None
  11.     raise ImportError, str(e) + '; please install the python-profiler package'
  12.  
  13. import hotshot.log as hotshot
  14. from hotshot.log import ENTER, EXIT
  15.  
  16. def load(filename):
  17.     return StatsLoader(filename).load()
  18.  
  19.  
  20. class StatsLoader:
  21.     
  22.     def __init__(self, logfn):
  23.         self._logfn = logfn
  24.         self._code = { }
  25.         self._stack = []
  26.         self.pop_frame = self._stack.pop
  27.  
  28.     
  29.     def load(self):
  30.         p = Profile()
  31.         p.get_time = _brokentimer
  32.         log = hotshot.log.LogReader(self._logfn)
  33.         taccum = 0
  34.         for event in log:
  35.             (filename, lineno, funcname) = (what,)
  36.             tdelta = event
  37.             if tdelta > 0:
  38.                 taccum += tdelta
  39.             
  40.             if what == ENTER:
  41.                 frame = self.new_frame(filename, lineno, funcname)
  42.                 p.trace_dispatch_call(frame, taccum * 1e-06)
  43.                 taccum = 0
  44.                 continue
  45.             if what == EXIT:
  46.                 frame = self.pop_frame()
  47.                 p.trace_dispatch_return(frame, taccum * 1e-06)
  48.                 taccum = 0
  49.                 continue
  50.         
  51.         if not not (self._stack):
  52.             raise AssertionError
  53.         return pstats.Stats(p)
  54.  
  55.     
  56.     def new_frame(self, *args):
  57.         
  58.         try:
  59.             code = self._code[args]
  60.         except KeyError:
  61.             code = FakeCode(*args)
  62.             self._code[args] = code
  63.  
  64.         if self._stack:
  65.             back = self._stack[-1]
  66.         else:
  67.             back = None
  68.         frame = FakeFrame(code, back)
  69.         self._stack.append(frame)
  70.         return frame
  71.  
  72.  
  73.  
  74. class Profile(profile.Profile):
  75.     
  76.     def simulate_cmd_complete(self):
  77.         pass
  78.  
  79.  
  80.  
  81. class FakeCode:
  82.     
  83.     def __init__(self, filename, firstlineno, funcname):
  84.         self.co_filename = filename
  85.         self.co_firstlineno = firstlineno
  86.         self.co_name = self.__name__ = funcname
  87.  
  88.  
  89.  
  90. class FakeFrame:
  91.     
  92.     def __init__(self, code, back):
  93.         self.f_back = back
  94.         self.f_code = code
  95.  
  96.  
  97.  
  98. def _brokentimer():
  99.     raise RuntimeError, 'this timer should not be called'
  100.  
  101.